/*
 * globalvar_util.c
 *
 *  Created on: 2011-11-19
 *      Author: wang
 */

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <fcntl.h>
#define DEVNAME "/dev/globalvar" //the name specified when running mknod
int main()
{
	int fd,num = 0;
	fd = open(DEVNAME,O_RDWR,S_IRUSR|S_IWUSR);
	if(fd != -1)
	{
		read(fd,&num,sizeof(int));
		printf("The value of globalvar:%d\n",num);

		printf("Input a num to change globalvar:\n");
		scanf("%d",&num);
		write(fd,&num,sizeof(int));

		read(fd,&num,sizeof(int));
		printf("The value of globalvar:%d\n",num);

		close(fd);
		return 0;
	}
	else
	{
		printf("Device open error!\n");
		return -1;
	}
}
